# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>

_realname=webrtc-audio-processing-1
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.3
pkgrel=2
pkgdesc="AudioProcessing library based on Google's implementation of WebRTC (mingw-w64)"
url="https://freedesktop.org/software/pulseaudio/webrtc-audio-processing/"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
license=('custom')
depends=(
  "${MINGW_PACKAGE_PREFIX}-gcc-libs"
)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-cc"
  "${MINGW_PACKAGE_PREFIX}-meson"
  "${MINGW_PACKAGE_PREFIX}-pkgconf"
  "${MINGW_PACKAGE_PREFIX}-abseil-cpp"
)
source=("https://gitlab.freedesktop.org/pulseaudio/webrtc-audio-processing/-/archive/v${pkgver}/webrtc-audio-processing-v${pkgver}.tar.gz"
        "https://gitlab.freedesktop.org/pulseaudio/webrtc-audio-processing/-/merge_requests/38.patch"
        "002-Appease-MSYS2-UCRT64-GCC-14.patch::https://gitlab.freedesktop.org/pulseaudio/webrtc-audio-processing/-/commit/a949f1de.patch")
sha256sums=('b04404884e705464c1a2da0d5036ae0fc02d87ed150faa7da4536c99d6966660'
            '28404752438fdb9112c4d2fb4f03230db9a7a599442430be71c428718b4fb07d'
            'e791e2d88e0511d61950faed39bf0d40ef656c6b0bbf6943bf8b97feb3febac8')

prepare() {
  cd "${srcdir}/webrtc-audio-processing-v${pkgver}"

  # https://gitlab.freedesktop.org/pulseaudio/webrtc-audio-processing/-/merge_requests/38
  patch -Np1 -i "${srcdir}/38.patch"

  patch -p1 -i "${srcdir}"/002-Appease-MSYS2-UCRT64-GCC-14.patch
}

build() {
  mkdir -p build-${MSYSTEM} && cd build-${MSYSTEM}

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    meson setup \
      --prefix="${MINGW_PREFIX}" \
      --wrap-mode=nodownload \
      --auto-features=enabled \
      --buildtype=plain \
      ../webrtc-audio-processing-v${pkgver}

  meson compile
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  DESTDIR="${pkgdir}" meson install

  cd "${srcdir}/webrtc-audio-processing-v${pkgver}"
  install -Dm644 COPYING "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
